package nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * Created by Administrator on 2017/10/20 0020.
 */
public class Channel3
{
    public static void main(String[] args) throws Exception
    {
        File fin = new File("D:\\Android\\IdeaProj\\JavaDemo\\src\\main\\java\\nio\\1.txt");
        File fout = new File("D:\\Android\\IdeaProj\\JavaDemo\\src\\main\\java\\nio\\3.txt");
        FileChannel channelIn = new FileInputStream(fin).getChannel();
        FileChannel channelOut = new FileOutputStream(fout).getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(256);
        while(channelIn.read(buffer) != -1)
        {
            buffer.flip();
            channelOut.write(buffer);
            channelOut.position(fout.length());
            buffer.clear();
        }
        System.out.println("copy complete");
    }
}
